package com.pts.servlet.enterprise;


import com.pts.dao.Dao;
import com.pts.dao.EnterpriseDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//处理enterprise/list.jsp页面请求，转发到Yes/No页面
//功能是通过id删除公司

@WebServlet("/enterdel")
public class DelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String username = request.getParameter("username");
        request.setAttribute("username",username);
        String str = request.getParameter("id");
        if("".equals(str)||str==null){
            request.getRequestDispatcher("admin/enterprise/Error.jsp").forward(request,response);
        }
        int id = Integer.parseInt(str);
        request.setAttribute("result","删除");
        Dao enterpriseDao = new EnterpriseDao();
        if(enterpriseDao.delete(id)){
            request.getRequestDispatcher("admin/enterprise/Yes.jsp").forward(request,response);
        }
        else{
            request.getRequestDispatcher("admin/enterprise/Error.jsp").forward(request,response);
        }
    }
}
